<template>
  <div class="post-comment">
    <van-field
      class="post-field"
      v-model="message"
      rows="2"
      autosize
      type="textarea"
      maxlength="50"
      placeholder="优质评论将会被优先展示"
      show-word-limit
    />
    <van-button
      type="primary"
      size="small"
      @click="onPost"
    >发布</van-button>
  </div>
</template>

<script>
import { addComment } from '@/api/comment'
// import eventBus from '@/utils/eventBus.js'
export default {
  name: 'CommentPost',
  components: {},
  props: {
    // 文章评论,传文章id
    // 评论的评论,传评论id
    target: [String, Number],
    articleId: [String, Number]
  },
  data () {
    return {
      message: ''
    }
  },
  computed: {},
  watch: {},
  created () {},
  mounted () {},
  methods: {
    async onPost () {
      if (this.message.trim() === '') return
      // 返回数据中,包含评论单项显示内容太
      const res = await addComment({
        target: this.target,
        art_id: this.articleId,
        content: this.message
      })
      // eventBus.$emit('onPostSucces', res.data.data.new_obj)
      // 提示成功
      this.$toast.success('新增成功')
      // 关闭弹层&添加新评论到列表最上面
      this.$emit('success', res.data.data.new_obj)
    }
  }
}
</script>

<style scoped lang="less">
.van-button--primary{
  height: 176px;
}
.post-comment {
  display: flex;
  padding: 15px;
  align-items: flex-end;
  .post-field {
    background: #f5f7f9;
    margin-right: 15px;
  }
}
</style>
